<?

/**
* local collection functions of tocmenu_12
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLFetchers
*
*/

/**
* @package CLFetchers
*
*/
class CLFetchers{

  /**
   * data detail
   *
   * @param object    $Db
   * @param integer   $modelId
   * @param Composer  $SourceDb
   * @param integer   $nDetail
   * @param array     $lstDetail
   */
  function fetchLstDataDetail(&$Db,
                              &$modelId,
                              &$SourceDb,
                              &$nDetail,
                              &$lstDetail){

    $query	= "SELECT M.MODEL,
                      D.QTY

               FROM ".$SourceDb->fetchValue("srcDbHdr")." M,
                    ".$SourceDb->fetchValue("srcDbDtl")." D

               WHERE	D.MODEL_ID='".$modelId."'
                      AND M.MODEL_ID=D.COMPOS_MODEL_ID";

    $Db->execFetchQuery($query,
                        $nDetail,
                        $lstDetail);
  }

  /**
   * data header
   *
   * @param object  $Db
   * @param integer $modelId
   * @param string  $srcDb
   * @param integer $nHeader
   * @param array   $lstHeader
   */
  function fetchLstDataHeader(&$Db,
                              &$modelId,
                              &$srcDb,
                              &$nHeader,
                              &$lstHeader){

    $query	= "SELECT MODEL
               FROM ".$srcDb."
               WHERE	MODEL_ID='".$modelId."' ";

    $Db->execFetchQuery($query,
                        $nHeader,
                        $lstHeader);
  }

  /**
   * model id
   *
   * @param object  $Db
   * @param string  $model
   * @param string  $srcDb
   * @param integer $modelId
   */
  function fetchModelId(&$Db,
                        &$model,
                         $srcDb,
                        &$modelId){

    $query	= "SELECT MODEL_ID
               FROM ".$srcDb."
               WHERE	MODEL='".$model."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $modelId = $result["MODEL_ID"][0];
  }

  /**
   * list of model
   *
   * @param object  $Db
   * @param boolean $isAll
   * @param string  $srcDb
   * @param array   $lstModel
   */
  function fetchLstModel(&$Db,
                         &$isAll,
                          $srcDb,
                         &$lstModel){

    if($isAll == 1){

      $condt = " ";
    }else{

      $condt = "WHERE TYPE<>"._MODEL_TYPE_NORMAL." ";
    }

    $query	= "SELECT MODEL
               FROM ".$srcDb."
               ".$condt."
               ORDER BY MODEL ASC ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $lstModel = $result["MODEL"];
  }

  /**
   * list of transaction
   *
   * @param object  $Db
   * @param string  $condt
   * @param string  $srcDbHdr
   * @param integer $nrows
   * @param array   $res
   */
  function fetchLstTransaction(&$Db,
                                $condt,
                               &$SourceDb,
                               &$nrows,
                               &$result){

    $query  = "SELECT DISTINCT
                      M.SER_NUMBER,
                      M.STATUS,
                      M.MODEL,
                      D.MODEL_ID

               FROM ".$SourceDb->fetchValue("srcDbHdr")." M,
                    ".$SourceDb->fetchValue("srcDbDtl")." D

               WHERE  M.MODEL_ID=D.MODEL_ID
               ORDER BY M.MODEL ASC";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);
  }
}

?>